// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    
    all: cc.Node = null;
    allScript: cc.Component = null;

    play: cc.Label = null;
    
    onLoad () {
        this.all = cc.find('Canvas/bg');
        this.allScript = this.all.getComponent('choice');

        if(this.play.node.on){
            this.onClicked1();
        }

        if(this.play.node.on){
            this.onClicked2();
        }
        
        if(this.play.node.on){
            this.onClicked3();
        }
        if(this.play.node.on){
            this.onClicked4();
        }
        //this.node.on('touchstart', this.onClicked1, this);
        //this.node.on('touchstart', this.onClicked2, this);
        //this.node.on('touchstart', this.onClicked3, this);
        //this.node.on('touchstart', this.onClicked4, this);
        this.node.on('touchstart', this.onClicked5, this);
    }

    onClicked1(){
        //cc.log(this.allScript.choices);
        if(this.allScript.choices == 0){
            //错误
            //this.allScript.choices = 0;
            cc.log("第一题错误");
        }
        if(this.allScript.choices == 1){
            //正确
            this.all = cc.find('Canvas/bg/question1');
            this.all.active = false;
            this.all = cc.find('Canvas/bg/question2');
            this.all.active = true;
            //this.allScript.choices = 0;
        }
    }

    onClicked2(){
        cc.log("CLicked2" + this.count);
        //cc.log(this.allScript.choices);
        if(this.allScript.choices == 0){
            //错误
            //this.allScript.choices = 0;
            cc.log(this.allScript.choices);
        }
        if(this.allScript.choices == 1){
            //正确
            this.all = cc.find('Canvas/bg/question2');
            this.all.active = false;
            this.all = cc.find('Canvas/bg/question3');
            this.all.active = true;

            //this.allScript.choices = 0;
            cc.log(this.allScript.choices);
        }
    }

    onClicked3(){
        //cc.log(this.allScript.choices);
        if(this.allScript.choices == 0){
            //错误
            //this.allScript.choices = 0;
        }
        if(this.allScript.choices == 1){
            //正确
            this.all = cc.find('Canvas/bg/question3');
            this.all.active = false;
            this.all = cc.find('Canvas/bg/question4');
            this.all.active = true;
            //this.allScript.choices = 0;
            cc.log(this.allScript.choices);
        }
        this.count++;
    }

    onClicked4(){
        //cc.log(this.allScript.choices);
        if(this.allScript.choices == 0){
            //错误
            //this.allScript.choices = 0;
        }
        if(this.allScript.choices == 1){
            //正确
            this.all = cc.find('Canvas/bg/question4');
            this.all.active = false;
            this.all = cc.find('Canvas/bg/question5');
            this.all.active = true;
            //this.allScript.choices = 0;
            cc.log(this.allScript.choices);
        }
    }

    onClicked5(){
        //cc.log(this.allScript.choices);
        if(this.allScript.choices == 0){
            //错误
            //this.allScript.choices = 0;
        }
        if(this.allScript.choices == 1){
            //正确
            this.all = cc.find('Canvas/bg/question5');
            this.all.active = false;
            this.all = cc.find('Canvas/bg/question6');
            this.all.active = true;
            //this.allScript.choices = 0;
            cc.log(this.allScript.choices);
        }
    }
    

    start () {

    }

    // update (dt) {}
}
